package constant.milk.periodapp.tip;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
import constant.milk.periodapp.R;
import constant.milk.periodapp.SuperActivity;

public class TipInfoActivity extends SuperActivity
{
	public static final String TIP_ID = "TIP_ID";
	
	private ViewPager infoPagerView;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		isAdFlag = false;
		
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.tip_info_activity);
		
		setFindViewId();
		setOnClick();
		setData();
	}

	@Override
	protected void setFindViewId()
	{
		infoPagerView = (ViewPager) findViewById(R.id.tipInfoTextView);
	}

	@Override
	protected void setOnClick()
	{
	}

	@Override
	protected void setData()
	{
		Intent intent = getIntent();
		int id = intent.getIntExtra(TIP_ID, 0);
		
		TipPagerAdapter adapter = new TipPagerAdapter();
		infoPagerView.setAdapter(adapter);
		infoPagerView.setCurrentItem(id);
	}


	/**
	 * 도움말의 내용을 번호 플래그에 맞게 가져와서 리턴한다.
	 * @param tipFlag
	 * @return
	 */
	private int getTip(int tipFlag)
	{
		int resources = 0;
		
		switch (tipFlag)
		{
			case 0:
			{
				resources = R.drawable.bg_tip1;
				break;
			}
			case 1:
			{
				resources = R.drawable.bg_tip2;
				break;
			}
			case 2:
			{
				resources = R.drawable.bg_tip3;
				break;
			}
			case 3:
			{
				resources = R.drawable.bg_tip4;
				break;
			}
			case 4:
			{
				resources = R.drawable.bg_tip5;
				break;
			}
			case 5:
			{
				resources = R.drawable.bg_tip6;
				break;
			}
		}
		
		return resources;
	}
	
	private class TipPagerAdapter extends PagerAdapter
	{
		public TipPagerAdapter(){};
		
		@Override
		public int getCount()
		{
			return 6;
		}

		@Override
		public Object instantiateItem(ViewGroup container, int position)
		{
			TextView textView = new TextView(superContext);
			
			LayoutParams params = new LayoutParams(
					LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
			
			textView.setLayoutParams(params);
			
			textView.setBackgroundResource(getTip(position));
			
			infoPagerView.addView(textView, 0);
			
			return textView;
		}
		
		@Override        
		public void destroyItem(View pager, int position, Object view) 
		{                
			((ViewPager)pager).removeView((View)view);        
		}                 
		
		@Override        
		public boolean isViewFromObject(View pager, Object obj) 
		{            
			return pager == obj;         
		}
	}
}
